﻿namespace WebPacker.Logger
{
	using System.Text;
	using WebPacker.Configuration;
	using WebPacker.Packs;

	internal static class LogHelper
	{
		private const string Null = "(null)";

		public static string ToLogString(this PackInfo packInfo)
		{
			return packInfo != null ? ToString(packInfo.PackType, packInfo.Name) : ToString(PackType.Unknown, Null);
		}

		public static string ToLogString(this IPack pack)
		{
			return pack != null ? ToString(pack.PackType, pack.Name) : ToString(PackType.Unknown, Null);
		}

		public static string ToString(PackType packType, string packName)
		{
			return string.Format("\"{0}\" ({1})", packName, packType);
		}

		public static string ToString(PackType packType, string[] resources)
		{
			var builder = new StringBuilder();

			if (resources != null)
			{
				foreach (var resource in resources)
				{
					if (builder.Length > 0)
					{
						builder.Append(", ");
					}

					builder.Append('"').Append(resource).Append('"');
				}
			}
			else
			{
				builder.Append(Null);
			}

			builder.Append(" (").Append(packType).Append(")");

			return builder.ToString();
		}
	}
}
